package com.lgc.algorithm.selection;

/**
 * 选择排序
 * 时间复杂度为O(n*n)
 */
public class SelectionSort {
    public int[] selectionSort(int[] A, int n) {
        // write code here
        int temp;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                if (A[i] > A[j]) {
                    temp = A[i];
                    A[i] = A[j];
                    A[j] = temp;
                }
            }
        }
        return A;
    }

    public static void main(String[] args) {
        SelectionSort selSort = new SelectionSort();
        int[] A = {6,1, 2, 3, 5, 2, 3};
        int[] ASort = selSort.selectionSort(A, A.length);
        for (int i = 0; i < ASort.length; i++) {
            System.out.println(ASort[i]);
        }
    }

}
